<template>
  <!-- 定义格式在 index.scss ref的作用是获取当前dom元素-->
  <div id="index" ref="appRef">
    <div class="bg">
      <!-- 加载动画 loading -->
      <dv-loading v-if="loading">Loading...</dv-loading>
      <!-- class="host-body" 没有定义，是用来定位的-->
      <div v-else class="host-body">
        <!-- class="d-flex jc-center"好像是和布局有关，d-flex {display: flex;}，-->
        <!-- jc-center:{ justify-content: center} -->
        <div class="d-flex jc-center">
          <!-- dv-decoration-10 datav中的装饰条-->
          <!--dv-dec-10：      width: 33.3%; height: 5px; -->
          <dv-decoration-10 class="dv-dec-10" />
          <!-- class="d-flex jc-center"好像是和布局有关，d-flex {display: flex;}，-->
          <!-- jc-center:{ justify-content: center} -->
          <div class="d-flex jc-center">
            <!--class="dv-dec-8"       width: 200px; height: 50px; -->
            <dv-decoration-8 class="dv-dec-8" :color="decorationColor" />
            <!-- position: relative; width: 500px;text-align: center; background-size: cover;background-repeat: no-repeat; -->
            <div class="title">
              <span class="title-text">大数据可视化监测平台</span>
              <dv-decoration-6
                class="dv-dec-6"
                :reverse="true"
                :color="['#50e3c2', '#67a1e5']"
              />
            </div>
            <dv-decoration-8
              class="dv-dec-8"
              :reverse="true"
              :color="decorationColor"
            />
          </div>
          <dv-decoration-10 class="dv-dec-10-s" />
        </div>

        <!-- 第二行 -->
        <div class="d-flex jc-between px-2">
          <div class="d-flex aside-width">
            <div class="react-left ml-4 react-l-s">
              <span class="react-left"></span>
              <span class="text">数据分析1</span>
            </div>
            <div class="react-left ml-3">
              <span class="text">数据分析2</span>
            </div>
          </div>
          <div class="d-flex aside-width">
            <div class="react-right bg-color-blue mr-3">
              <span class="text fw-b">数据展示</span>
            </div>
            <div class="react-right mr-4 react-l-s">
              <span class="react-after"></span>
              <span class="text"
                >{{ dateYear }} {{ dateWeek }} {{ dateDay }}</span
              >
            </div>
          </div>
        </div>

        <div class="body-box">
          <!-- 第三行数据 -->
          <div class="content-box">
            <div>
              <dv-border-box-12>
                <centerLeft1 />
              </dv-border-box-12>
            </div>
            <div>
              <dv-border-box-12>
                <centerLeft2 />
              </dv-border-box-12>
            </div>
            <!-- 中间 -->
            <div>
              <center />
            </div>
            <!-- 中间 -->
            <div>
              <centerRight2 />
            </div>
            <div>
              <dv-border-box-13>
                <centerRight1 />
              </dv-border-box-13>
            </div>
          </div>

          <!-- 第四行数据 -->
          <div class="bottom-box">
            <dv-border-box-8>
              <div class="bottom-left-box">
                <div class="dv-border-box-self bg-color-black">
                  <dv-border-box-10 :reverse="true">
                    <lineChart></lineChart>
                  </dv-border-box-10>
                </div>
                <div class="dv-border-box-self bg-color-black">
                  <dv-border-box-10>
                    <h1
                      style="
                        position: absolute;
                        top: 50%;
                        left: 50%;
                        transform: translate(-50%, -50%);
                      "
                    >
                      预留模块1
                    </h1>
                  </dv-border-box-10>
                </div>
                <div class="dv-border-box-self">
                  <dv-border-box-10>
                    <h1
                      style="
                        position: absolute;
                        top: 50%;
                        left: 50%;
                        transform: translate(-50%, -50%);
                      "
                    >
                      预留模块2
                    </h1>
                  </dv-border-box-10>
                </div>
                <div class="dv-border-box-self">
                  <dv-border-box-10>
                    <h1
                      style="
                        position: absolute;
                        top: 50%;
                        left: 50%;
                        transform: translate(-50%, -50%);
                      "
                    >
                      预留模块3
                    </h1></dv-border-box-10
                  >
                </div>

              </div>
            </dv-border-box-8>
            <dv-border-box-8>
              <bottomRight />
            </dv-border-box-8>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import drawMixin from "../utils/drawMixin";
// 引入一个 mixin，可能包含一些绘图相关的逻辑
import { formatTime } from "../utils/index.js";
// 引入一个工具函数，用于格式化时间
import centerLeft1 from "./centerLeft1";
// 引入左上角第一个模块的组件
import centerLeft2 from "./centerLeft2";
// 引入左上角第二个模块的组件
import centerRight1 from "./centerRight1";
// 引入右上角第一个模块的组件
import centerRight2 from "./centerRight2";
// 引入右上角第二个模块的组件
import center from "./center";
// 引入中间模块的组件

// 引入左下角模块的组件
import bottomRight from "./bottomRight";
// 引入右下角模块的组件
import lineChart from "@/components/myComponents/lineChart/index";
// import axios from "axios";  // 引入axios
import { getHello } from "@/api/test.js";
export default {
  mixins: [drawMixin],
  // 使用 drawMixin
  data() {
    return {
      timing: null,
      // 用于存储定时器的标识
      loading: true,
      // 是否处于加载状态
      dateDay: null,
      // 当前时间（时分秒）
      dateYear: null,
      // 当前日期（年月日）
      dateWeek: null,
      // 当前星期几
      weekday: ["周日", "周一", "周二", "周三", "周四", "周五", "周六"],
      // 星期的数组
      decorationColor: ["#568aea", "#000000"],
      // 装饰颜色
    };
  },
  components: {
    centerLeft1,
    centerLeft2,
    centerRight1,
    centerRight2,
    center,
    lineChart,
    bottomRight,
  },
  async created() {
    const res = await getHello();
    console.log(res);
  },
  // 注册所有子组件
  mounted() {
    this.timeFn();
    // 调用 timeFn 方法，开始更新时间和日期
    this.cancelLoading();
    // 调用 cancelLoading 方法，结束加载状态
  },
  beforeDestroy() {
    clearInterval(this.timing);
    // 在组件销毁前清除定时器
  },
  methods: {
    timeFn() {
      this.timing = setInterval(() => {
        // 每隔 1 秒更新时间和日期
        this.dateDay = formatTime(new Date(), "HH: mm: ss");
        // 更新当前时间
        this.dateYear = formatTime(new Date(), "yyyy-MM-dd");
        // 更新当前日期
        this.dateWeek = this.weekday[new Date().getDay()];
        // 更新当前星期几
      }, 1000);
    },
    cancelLoading() {
      setTimeout(() => {
        this.loading = false;
        // 500 毫秒后将 loading 状态设置为 false，结束加载动画
      }, 500);
    },
  },
};
</script>
<style lang="scss" scoped>
@import "../assets/scss/index.scss";
.bottom-left-box {
  width: 100%; /* 或者具体的宽度 */
  height: 100%;

  display: grid;
  grid-template-columns: repeat(2, 1fr); /* 定义三列，每列宽度相等 */
  grid-template-rows: repeat(2, 1fr); /* 定义两行，每行高度相等 */
}
.dv-border-box-self {
  margin: 5px;
}
</style>
